import pinia from '/@/stores/index';
import {useEmployeeStore} from '/@/stores/employee-info';
import { judementSameArr } from '/@/utils/arrayOperation';

/**
 * 单个权限验证
 * @param value 权限值
 * @returns 有权限，返回 `true`，反之则反
 */
export function auth(value: string): boolean {
	const employeeStore = useEmployeeStore(pinia);
	const employee = employeeStore.getEmployeeInfo();
	const funcIdList: string[] = employee.funcIdList;
	return funcIdList.some((v: string) => v === value);
}

/**
 * 多个权限验证，满足一个则为 true
 * @param value 权限值
 * @returns 有权限，返回 `true`，反之则反
 */
export function auths(value: Array<string>): boolean {
	let flag = false;
	const employeeStore = useEmployeeStore(pinia);
	const employee = employeeStore.getEmployeeInfo();
	const funcIdList: string[] = employee.funcIdList;
	funcIdList.map((val: string) => {
		value.map((v: string) => {
			if (val === v) flag = true;
		});
	});
	return flag;
}

/**
 * 多个权限验证，全部满足则为 true
 * @param value 权限值
 * @returns 有权限，返回 `true`，反之则反
 */
export function authAll(value: Array<string>): boolean {
	const employeeStore = useEmployeeStore(pinia);
	const employee = employeeStore.getEmployeeInfo();
	const funcIdList: string[] = employee.funcIdList;
	return judementSameArr(value, funcIdList);
}
